<?php
class EntityFactory implements Factory{

	/**
	 * (non-PHPdoc)
	 * @see library/Factory/Factory::getInstance()
	 * @param ControllerRoute $route
	 * @return Controller
	 */
	public function getInstance($route){
		return null;
	}
	/**
	 * Get Entity by Class ...
	 * @param string $context
	 * @return EntityInterface.
	 */
	public static function instance($context){
		$entityPath = Configuration::ENTITY_FOLDER
		. SLASH
		. $context .'.php';
		if(file_exists($entityPath)){
			include_once $entityPath;
			if(!class_exists($context)){
				Log::error("EntityFactory", "Class " . $context . " Not found");
				if(Configuration::DEBUG_MOD)
				throw new EntityException("Class " . $context . " Not found");
				return new BaseEntity();
			}
			return new $context;
		}
		else {
			Log::error("EntityFactory", "File " . $entityPath . " Not found");
			if(Configuration::DEBUG_MOD)
			throw new EntityException("File " . $entityPath . " Not found");
			return new BaseEntity();
		}
	}
}